package com.cpe.web.controller.classs;

import static com.sql.data.response.CommonRespCode.EXCEPTION;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cpe.data.domain.classs.Class;
import com.cpe.data.domain.classs.ClassQuery;
import com.cpe.repository.mapper.classs.ClassMapper;
import com.cpe.web.controller.AbstractController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sql.data.response.JsonResponse;

import lombok.extern.slf4j.Slf4j;

/**
 * 班级信息
 */
@Slf4j
@RestController
@RequestMapping("/classes")
public class ClassController extends AbstractController {

	@Resource
	private ClassMapper classMapper;

	/**
	 * 分页条件查询
	 */
	@RequestMapping(method = GET)
	public JsonResponse getPage(HttpServletRequest request, ClassQuery query) {
		try {
			// 进行分页查询
			PageHelper.startPage(query.pageWhitoutOrder());
			List<Class> classes = classMapper.findAll();
			return JsonResponse.ok(new PageInfo<>(classes));
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return JsonResponse.custom(EXCEPTION);
		}
	}
}
